package controller

import "C"
import (
	"fmt"
	"github.com/garyburd/redigo/redis"
	_ "github.com/garyburd/redigo/redis"
	"github.com/gin-gonic/gin"
	"test/common"
	"test/model"
)



func Manger_Login(ctx *gin.Context) {
	//redis连接
	c,err := redis.Dial("tcp","localhost:6379")
	if err != nil {
		fmt.Println("conn redis failed，err:",err)
		return
	}
	r,err := redis.String(c.Do("Get","admin"))
	if err != nil {
		fmt.Println(err)
	}
	if r == "admin" {
		ctx.JSON(200, gin.H{
			"code": 200,
			"msg": "登录成功",
		})
		return
	}
	//获取参数
	db := common.GetDB()
	requestUser := make(map[string]interface{})
	var manger model.Manger
	db.Last(&manger)
	ctx.ShouldBind(&requestUser)
	mname:=requestUser["username"].(string)
	password:=requestUser["password"].(string)
	//数据验证
	if mname != "admin" {
		fmt.Println("我执行了")
		ctx.JSON(200,gin.H{
			"code":200,
			"msg":"用户不存在",
		})
		return
	}
	//判断密码是否正确
	if password != "admin" {
		fmt.Println("我执行了")
		ctx.JSON(200,gin.H{
			"code":200,
			"msg":"用户不存在",
		})
		return
	}
	//r,err := redis.String(c.Do("Get","nike"))
	//if err != nil {
	//	fmt.Println(err)
	//	return
	//}
	//fmt.Println(r)
	//返回结果
	ctx.JSON(200, gin.H{
		"code": 200,
		"msg": "登录成功",
	})
}
